<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加工具 - 家庭工具管理</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" href="styles.css">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#FF7EB9',
                        secondary: '#B983FF',
                        accent: '#FFC2E2',
                        light: '#FFF9FC',
                        dark: '#5D4037'
                    },
                    boxShadow: {
                        'custom': '0 4px 15px rgba(255, 126, 185, 0.15)',
                    }
                },
            }
        }
    </script>
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .gradient-bg {
                background: linear-gradient(135deg, #FF7EB9 0%, #B983FF 100%);
            }
            .card-shadow {
                box-shadow: 0 4px 20px rgba(255, 126, 185, 0.1);
            }
        }
    </style>
</head>
<body class="bg-gray-50 h-full">
    <!-- 页面内容 -->
    <div class="h-full flex flex-col">
        <!-- 顶部导航栏 -->
        <div class="gradient-bg text-white shadow-md">
            <div class="flex items-center justify-between px-4 py-3">
                <button onclick="window.parent.navigateTo('home.html')" class="p-2 bg-white/20 rounded-full hover:bg-white/30 transition-colors">
                    <i class="fa fa-arrow-left"></i>
                </button>
                <h1 class="text-lg font-medium">添加工具</h1>
                <button class="px-4 py-1.5 bg-white text-primary font-medium rounded-full hover:bg-white/90 transition-colors">保存</button>
            </div>
        </div>
        
        <!-- 表单内容 -->
        <div class="flex-1 overflow-y-auto">
            <div class="bg-white rounded-t-3xl p-6 card-shadow">
                <!-- 工具图片上传 -->
                <div class="mb-5">
                    <label class="block text-sm font-medium text-gray-700 mb-2">工具照片</label>
                    <div class="flex space-x-3">
                        <div class="w-24 h-24 rounded-2xl overflow-hidden bg-accent/30 flex items-center justify-center border-2 border-dashed border-primary/30 hover:border-primary/50 transition-colors cursor-pointer">
                            <i class="fa fa-camera text-primary text-xl"></i>
                        </div>
                        <div class="text-sm text-gray-500 self-center">点击添加照片</div>
                    </div>
                </div>
                
                <!-- 基本信息 -->
                <div class="space-y-4">
                    <div>
                        <label for="toolName" class="block text-sm font-medium text-gray-700 mb-1">工具名称 <span class="text-red-500">*</span></label>
                        <input type="text" id="toolName" class="form-input w-full rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-3 transition-all" placeholder="例如：电动螺丝刀">
                    </div>
                    
                    <div>
                        <label for="toolCategory" class="block text-sm font-medium text-gray-700 mb-1">工具类别 <span class="text-red-500">*</span></label>
                        <div class="relative">
                            <select id="toolCategory" class="form-input w-full appearance-none pr-8 rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-3 transition-all">
                                <option value="">请选择类别</option>
                                <option value="1">电动工具 → 钻孔类 → 电钻</option>
                                <option value="2">电动工具 → 螺丝刀类 → 电动螺丝刀</option>
                                <option value="3">手动工具 → 测量类 → 卷尺</option>
                                <option value="4">手动工具 → 紧固类 → 扳手</option>
                                <option value="5">园艺工具 → 修剪类 → 修枝剪</option>
                            </select>
                            <div class="absolute inset-y-0 right-0 flex items-center px-2 pointer-events-none">
                                <i class="fa fa-chevron-down text-gray-400 text-xs"></i>
                            </div>
                        </div>
                    </div>
                    
                    <div>
                        <label for="toolBrand" class="block text-sm font-medium text-gray-700 mb-1">品牌</label>
                        <input type="text" id="toolBrand" class="form-input w-full rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-3 transition-all" placeholder="例如：博世">
                    </div>
                    
                    <div>
                        <label for="purchaseDate" class="block text-sm font-medium text-gray-700 mb-1">购买日期</label>
                        <div class="relative">
                            <input type="date" id="purchaseDate" class="form-input w-full rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-3 transition-all">
                        </div>
                    </div>
                    
                    <div>
                        <label for="toolPrice" class="block text-sm font-medium text-gray-700 mb-1">价格</label>
                        <div class="relative">
                            <div class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
                                <span class="text-gray-500">¥</span>
                            </div>
                            <input type="number" id="toolPrice" class="form-input w-full pl-8 rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-3 transition-all" placeholder="0.00" step="0.01">
                        </div>
                    </div>
                    
                    <div>
                        <label for="warrantyPeriod" class="block text-sm font-medium text-gray-700 mb-1">保修期限（月）</label>
                        <input type="number" id="warrantyPeriod" class="form-input w-full rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-3 transition-all" placeholder="例如：24">
                    </div>
                    
                    <div>
                        <label for="toolSize" class="block text-sm font-medium text-gray-700 mb-1">尺寸</label>
                        <input type="text" id="toolSize" class="form-input w-full rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-3 transition-all" placeholder="例如：180mm × 50mm × 25mm">
                    </div>
                    
                    <div>
                        <label for="toolWeight" class="block text-sm font-medium text-gray-700 mb-1">重量</label>
                        <input type="text" id="toolWeight" class="form-input w-full rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-3 transition-all" placeholder="例如：0.8kg">
                    </div>
                    
                    <div>
                        <label for="toolColor" class="block text-sm font-medium text-gray-700 mb-1">颜色</label>
                        <input type="text" id="toolColor" class="form-input w-full rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-3 transition-all" placeholder="例如：蓝色">
                    </div>
                    
                    <div>
                        <label for="specialFeatures" class="block text-sm font-medium text-gray-700 mb-1">特殊功能</label>
                        <textarea id="specialFeatures" rows="3" class="form-input w-full rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-3 transition-all" placeholder="描述工具的特殊功能"></textarea>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">状态</label>
                        <div class="flex flex-wrap gap-2">
                            <button class="px-4 py-1.5 bg-primary text-white text-sm rounded-full shadow-md hover:shadow-lg transition-shadow">在用</button>
                            <button class="px-4 py-1.5 bg-gray-50 text-gray-600 text-sm rounded-full hover:bg-gray-100 transition-colors">闲置</button>
                            <button class="px-4 py-1.5 bg-gray-50 text-gray-600 text-sm rounded-full hover:bg-gray-100 transition-colors">损坏</button>
                            <button class="px-4 py-1.5 bg-gray-50 text-gray-600 text-sm rounded-full hover:bg-gray-100 transition-colors">已丢弃</button>
                            <button class="px-4 py-1.5 bg-gray-50 text-gray-600 text-sm rounded-full hover:bg-gray-100 transition-colors">已借出</button>
                        </div>
                    </div>
                    
                    <div>
                        <label for="toolLocation" class="block text-sm font-medium text-gray-700 mb-1">存放位置</label>
                        <div class="relative">
                            <select id="toolLocation" class="form-input w-full appearance-none pr-8 rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-3 transition-all">
                                <option value="">请选择位置</option>
                                <option value="1">车库 → 工具箱</option>
                                <option value="2">阳台 → 储物柜</option>
                                <option value="3">书房 → 抽屉</option>
                                <option value="4">厨房 → 刀架</option>
                            </select>
                            <div class="absolute inset-y-0 right-0 flex items-center px-2 pointer-events-none">
                                <i class="fa fa-chevron-down text-gray-400 text-xs"></i>
                            </div>
                        </div>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">标签</label>
                        <div class="flex flex-wrap gap-2 mb-2">
                            <span class="flex items-center px-3 py-1.5 bg-accent/30 text-dark text-sm rounded-full">
                                常用
                                <button class="ml-1 text-gray-400">
                                    <i class="fa fa-times-circle"></i>
                                </button>
                            </span>
                            <span class="flex items-center px-2 py-1 bg-gray-100 text-gray-600 text-sm rounded-full">
                                DIY
                                <button class="ml-1 text-gray-400">
                                    <i class="fa fa-times-circle"></i>
                                </button>
                            </span>
                        </div>
                        <div class="flex">
                            <input type="text" class="form-input flex-1 mr-2 rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-2.5 transition-all" placeholder="添加标签">
                            <button class="px-4 py-2 gradient-bg text-white text-sm rounded-xl hover:opacity-90 transition-opacity">添加</button>
                        </div>
                    </div>
                    
                    <div>
                        <label for="toolNotes" class="block text-sm font-medium text-gray-700 mb-1">备注</label>
                        <textarea id="toolNotes" rows="3" class="form-input w-full rounded-xl border border-gray-200 focus:border-primary focus:ring-2 focus:ring-primary/20 p-3 transition-all" placeholder="添加备注信息"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 页面加载完成后的处理
        document.addEventListener('DOMContentLoaded', function() {
            // 为状态按钮添加点击事件
            const statusButtons = document.querySelectorAll('.flex.flex-wrap.gap-2 button');
            statusButtons.forEach(button => {
                button.addEventListener('click', function() {
                    // 移除所有按钮的选中状态
                    statusButtons.forEach(btn => {
                        btn.classList.remove('bg-primary', 'text-white');
                        btn.classList.add('bg-gray-100', 'text-gray-600');
                    });
                    
                    // 设置当前按钮为选中状态
                    this.classList.remove('bg-gray-100', 'text-gray-600');
                    this.classList.add('bg-primary', 'text-white');
                });
            });
            
            // 为标签删除按钮添加点击事件
            const tagDeleteButtons = document.querySelectorAll('.fa-times-circle');
            tagDeleteButtons.forEach(button => {
                button.parentElement.addEventListener('click', function(e) {
                    e.preventDefault();
                    e.stopPropagation();
                    // 删除标签
                    this.closest('span').remove();
                });
            });
            
            // 为添加标签按钮添加点击事件
            document.querySelector('button.bg-primary.text-white.text-sm').addEventListener('click', function() {
                const input = this.parentElement.querySelector('input');
                const tagText = input.value.trim();
                
                if (tagText) {
                    // 创建新标签
                    const tagsContainer = this.closest('div').previousElementSibling;
                    const newTag = document.createElement('span');
                    newTag.className = 'flex items-center px-2 py-1 bg-gray-100 text-gray-600 text-sm rounded-full';
                    newTag.innerHTML = `
                        ${tagText}
                        <button class="ml-1 text-gray-400">
                            <i class="fa fa-times-circle"></i>
                        </button>
                    `;
                    
                    // 添加删除事件
                    newTag.querySelector('button').addEventListener('click', function(e) {
                        e.preventDefault();
                        e.stopPropagation();
                        newTag.remove();
                    });
                    
                    tagsContainer.appendChild(newTag);
                    input.value = '';
                }
            });
            
            // 为保存按钮添加点击事件
            document.querySelector('.text-primary.font-medium').addEventListener('click', function() {
                // 这里可以添加表单验证和保存逻辑
                alert('工具信息已保存！');
                window.parent.navigateTo('home.html');
            });
        });
    </script>
</body>
</html>